<template>
  <div>
    <p>禁选法定节假日</p>
    <el-date-picker
      v-model="weekValue"
      type="date"
      placeholder="请选择日期"
      :picker-options="pickerOptions"
      @change="changeWeek" />
  </div>
</template>

<script>
import { HOLIDAY } from './holiday'

const newDates = []
const Saturday = new Date('2019/12/28').getTime()
const Sunday = new Date('2019/12/29').getTime()
const baseTime = 3600 * 1000 * 24 * 7

for (var i = 1;i < 100;i++) {
  var sunday = new Date(Sunday + baseTime * i)
  var saturday = new Date(Saturday + baseTime * i)
  newDates.push(saturday.getFullYear() + '/' + (saturday.getMonth() + 1) + '/' + saturday.getDate())
  newDates.push(sunday.getFullYear() + '/' + (sunday.getMonth() + 1) + '/' + sunday.getDate())
}

// 合并两个数组
HOLIDAY.push(...newDates)
// 去重
const combainDates = Array.from(new Set(HOLIDAY))

export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          for (var i = 0; i < combainDates.length; i++) {
            if (time.getTime() === new Date(combainDates[i]).getTime()) {
              return true
            }
          }
          return false
        }
      },
      weekValue: '2019-09-09'
    }
  },
  methods: {
    changeWeek(e) {
      console.log(e.getTime())
    }
  }
}
</script>
